package com.xy.exam.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.xy.exam.pojo.dto.InfoAddNewDTO;
import com.xy.exam.pojo.dto.InfoUpdateDTO;
import com.xy.exam.service.IInfoService;
import com.xy.exam.service.IUserService;
import com.xy.exam.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


@Slf4j
@RequestMapping("/info")
@RestController
@Api(tags="02.考试信息管理")//添加模块名称
public class InfoController {
    @Autowired
    IInfoService infoService;
    @PostMapping("/add-new")
    @ApiOperation(value = "添加考试信息")//添加名称
    @ApiOperationSupport(order = 100)//排序
    public JsonResult addNew( InfoAddNewDTO infoAddNewDTO) {
        infoService.addNew(infoAddNewDTO);
        return new JsonResult().ok();
    }


    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除考试信息,根据id")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试信息ID", required = true, dataType = "long")
    })
    public JsonResult delete(@Range(min = 1, message = "删除考试信息失败，ID值无效！")
                             @PathVariable Long id) {
        infoService.delete(id);
        return JsonResult.ok();
    }


    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改考试信息信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试信息ID", required = true, dataType = "long")
    })
    public JsonResult updateInfoById(@Range(min = 1, message = "修改考试信息信息失败，ID值无效！")
                                     @PathVariable Long id, @Valid InfoUpdateDTO infoUpdateDTO) {
        infoService.updateInfoById(id, infoUpdateDTO);
        return JsonResult.ok();
    }


    @GetMapping("/{id:[0-9]+}/select")
    @ApiOperation("查询公告详情,根据id")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "考试信息ID", required = true, dataType = "long")
    })
    public JsonResult getStandardById(@Range(min = 1, message = "获取考试信息信息失败，ID值无效！")
                                      @PathVariable Long id) {

       
        return JsonResult.ok( infoService.getStandardById(id));
    }


    @GetMapping("/list")
    @ApiOperation("查询考试信息列表")
    @ApiOperationSupport(order = 420)
    public JsonResult list() {

        return JsonResult.ok(infoService.list());
    }
}
